package com.test.math;

import java.util.Random;

public class NumberDemo {

    public static void main(String[] args) {
        for (int i = 0; i < 1000; i++) {
            test1();
        }
        System.out.println(String.format("%04d", 777777));
    }

    public static void test() {
        System.out.println(String.format("%04d", (int) (Math.random() * (9999 - 1000 + 1)) + 1000));
    }

    public static void test1() {
        System.out.println(String.valueOf((int) (Math.random() * (9999 - 1000 + 1)) + 1000));
    }

    public static void testAll() {
        String msg = "您的注册码为%s,谢谢注册!";

        System.out.println("Math.random得到小数");
        System.out.println(Math.round((Math.random() + 1) * 1000));
        System.out.println("Random");
        System.out.println(new Random().nextInt(9999));
        System.out.println("字符串前面补0的话就这样String.format");
        System.out.println(String.format("%04d", new Random().nextInt(9999)));
    }
}
